package com.cn.wanxi.servlet.user;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.model.UserModel;
import com.cn.wanxi.service.UserService;
import com.cn.wanxi.service.impl.UserServiceImpl;
import com.cn.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/user/enable")
public class UserUpdateEnableServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

//        0.乱码处理
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
//        req就是前端请求后台
//        resp 响应，后台响应前端
//        我们这么拿到前端传递给后台的数据呢？
//        1.得到前端数据
        String id = req.getParameter("id");
//       2. 封装对象
        UserModel userModel = new UserModel();
        userModel.setId(Tool.strToInt(id));
//        3.调用服务逻辑层,写逻辑代码的地方
        UserService userService = new UserServiceImpl();
//        4.得到逻辑层返回数据

        ResultModel resultModel = userService.updateEnable(userModel);

//        5.将数据返回给前端
        resp.getWriter().println(JSONObject.toJSONString(resultModel));
    }
}
